package com.yesorno.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.yesorno.constants.Constants;
import com.yesorno.ui.CustomTitleActivity;
import com.yesorno.ui.MyMenuList;

public class EditUserPropertyActivity extends CustomTitleActivity {

	private Button goBack;
	private Button save;

	private EditText edit_user_property_property;

	RegBtnsClickListeners rbc = new RegBtnsClickListeners();

	private Long curUserId;

	private String editType;
	private String editValue;

	/**
	 * 注册页面按钮的监听类
	 * 
	 * @author samoin
	 * @date 2011-07-06
	 * @version 0.1
	 * 
	 */
	class RegBtnsClickListeners implements OnClickListener {
		@Override
		public void onClick(View v) {
			if (v == goBack) {
				Intent intent = new Intent();
				EditUserPropertyActivity.this.setResult(RESULT_OK, intent);
				EditUserPropertyActivity.this.finish();
			}
			if (v == save) {
				editValue = edit_user_property_property.getText().toString();
				// TODO 这里将来要与后台通讯，修改完信息
				Intent intent = new Intent();
				intent.putExtra("editType", editType);
				intent.putExtra("editValue", editValue);
				EditUserPropertyActivity.this.setResult(RESULT_OK, intent);
				EditUserPropertyActivity.this.finish();
			}
		}
	}

	@Override
	public void setTitleViews() {
		LinearLayout titleLayout = getTITLE_LAYOUT();
		// 返回按钮
		goBack = CustomTitleActivity
				.createTitleLeftButton(EditUserPropertyActivity.this,
						R.string.userinfo_title_btn_goback,
						Constants.TITLE_BTN_MARGIN1);
		goBack.setOnClickListener(rbc);
		titleLayout.addView((View) goBack.getParent());

		editType = getIntent().getStringExtra("editType");
		editValue = getIntent().getStringExtra("editValue");
		// 中间的资料的文字
		int id = R.string.edit_nickname_title;
		if (editType.equals("desc")) {
			id = R.string.edit_desc_title;
		}
		TextView tv = CustomTitleActivity.createTitleDesc(
				EditUserPropertyActivity.this, id, 0);
		titleLayout.addView((View) tv.getParent());

		save = CustomTitleActivity.createTitleRightButton(
				EditUserPropertyActivity.this, R.string.edit_user_info_save,
				Constants.TITLE_BTN_MARGIN2);
		LinearLayout ll = (LinearLayout) save.getParent();
		ll.setGravity(Gravity.RIGHT);
		save.setOnClickListener(rbc);
		titleLayout.addView(ll);
	}

	@Override
	public void setLayoutId() {
		setContentView(R.layout.edit_user_property);
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		curUserId = Constants.USER_ID;
		super.onCreate(savedInstanceState);
		((LinearLayout) findViewById(R.id.menus)).addView(new MyMenuList(
				EditUserPropertyActivity.this, 2));

		setMyView();

	}

	private void setMyView() {
		edit_user_property_property = (EditText) findViewById(R.id.edit_user_property_property);
		edit_user_property_property.setText(editValue);
	}

}
